# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Simon Sobisch <simonsobisch@gnu.org>

_realname=pdcurses
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.6
pkgrel=2
pkgdesc="Public Domain Curses wincon port (mingw-w64)"
arch=('any')
url="https://github.com/wmcbrine/PDCurses"
license=('public domain')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("https://github.com/wmcbrine/PDCurses/archive/${pkgver}.tar.gz"
        "001-mingw-pdcurses-3.6-build.patch")
sha256sums=('1760CBF3C3F254798E3614EFA40206F95FE5BB2CA68EB2BE434265D995F078EB'
            '98867A357E172CF18F9BD59FC8208F44EBBA6E887F6B87522E32CDA333CF416D')

prepare() {
  cd "${srcdir}/PDCurses-${pkgver}/wincon"
  patch -Np1 -i ${srcdir}/001-mingw-pdcurses-3.6-build.patch
}

build() {
  cd "${srcdir}/PDCurses-${pkgver}/wincon"

  make \
    CC=${MINGW_PREFIX}/bin/gcc \
    LINK=${MINGW_PREFIX}/bin/gcc \
    STRIP=${MINGW_PREFIX}/bin/strip \
    AR=${MINGW_PREFIX}/bin/ar \
    WIDE=Y \
    UTF8=Y \
    DLL=Y
}

package() {
  cd "${srcdir}/PDCurses-${pkgver}"

  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,include,lib}
  mkdir ${pkgdir}${MINGW_PREFIX}/include/pdcurses
 
  install wincon/*.exe ${pkgdir}${MINGW_PREFIX}/bin/
  install wincon/pdcurses.dll ${pkgdir}${MINGW_PREFIX}/bin/
  install wincon/pdcurses.a ${pkgdir}${MINGW_PREFIX}/lib/libpdcurses.dll.a

  echo '#include "pdcurses/curses.h"' > pdcurses.h
  install -m 0644 pdcurses.h ${pkgdir}${MINGW_PREFIX}/include/pdcurses.h
  install -m 0644 curses.h panel.h term.h ${pkgdir}${MINGW_PREFIX}/include/pdcurses/
}
